package com.example.customview

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val frameLayout = findViewById<FrameLayout>(R.id.layout)

        val customView = CustomView(this)
        customView.setOnTouchListener(View.OnTouchListener { view: View, motionEvent: MotionEvent ->
            customView.bitmapX = motionEvent.x
            customView.bitmapY = motionEvent.y
            customView.invalidate()
            true
        })

        //将自定义view添加进去framelayout中
        frameLayout.addView(customView)
    }


}
